package controleur;

import java.util.ArrayList;
import java.util.List;
import javax.faces.component.UIData;
import javax.faces.component.UISelectBoolean;

import demo.Customer;

public class BankControler {
	
	List<Customer> customers = new ArrayList<Customer>();
	
	private UIData datatable;
	private UISelectBoolean checkbox;

	public List<Customer> getCustomers() {
		return customers;
	}

	public void setCustomers(List<Customer> customers) {
		this.customers = customers;
	}

	public BankControler() {
		super();
		customers.add(new Customer("Jean","Claude"));
		customers.add(new Customer("Dupon","Pierre"));
		customers.add(new Customer("Paul","Michel"));
	}

	public void deleteCustomer() {
		int size = this.datatable.getRowCount();
		List<Customer> selectedCustomers = new ArrayList<Customer>();
		for (int i = 0; i < size; i++) {
			this.datatable.setRowIndex(i);
			if (this.checkbox.isSelected()) {
				selectedCustomers.add(this.customers.get(i));
			}
		}
		this.customers.removeAll(selectedCustomers);
	}

	public void addCustomer() {
		Customer customer = new Customer();
		customer.setName("Nouveau");
		customer.setForName("client");
		this.customers.add(customer);
	}	
	

	public String submit(){
        System.out.println(customers.get(0));
		return "ok";
	}

	public UIData getDatatable() {
		return datatable;
	}

	public void setDatatable(UIData datatable) {
		this.datatable = datatable;
	}

	public UISelectBoolean getCheckbox() {
		return checkbox;
	}

	public void setCheckbox(UISelectBoolean checkbox) {
		this.checkbox = checkbox;
	}

}
